******************************************************************************
* This program creates the key datasets and then produces Tables I-IV in 
* Greenwood, Hanson, Stein, and Sunderam, "A Quantity-Driven Theory of Term Premia
* and Exchange Rates". The corresponding author is Samuel Hanson, shanson@hbs.edu.
******************************************************************************


set more off
set matsize 5000
program drop _all
* set trace off
set type double
		
******************************************************************************
**************** Assemble data 
******************************************************************************
			
		***********************************************************************************
		*** Define program that assembles a panel of foreign bond yields and currencies ***
		***********************************************************************************
		
		program define assemble_panel

			***********************************
			*** Canadian zero-coupon yields ***
			*********************************** 

			*** Source: https://www.bankofcanada.ca/rates/interest-rates/bond-yield-curves/

				import excel using canada_yield_curves.xlsx, clear sheet(upload) firstrow
				drop if sveny10 == .
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				gen currency = "CAD"
				order ym currency
				save fx_panel_USD, replace

			********************************
			*** Swiss zero-coupon yields ***
			********************************
			
			*** Source: https://www.snb.ch/en/srv/id/contact

				import excel using swiss_yield_curves.xlsx, clear sheet(monthly_upload) firstrow
				drop if sveny10 == .
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				
				* Yields are quoted on an annual bond equivalent basis: take log(1+Y) to get continuously compounded equivalent		
				unab varlist: sven*
				foreach var of local varlist {
					replace `var' = 100*ln(1+`var'/100)	
				}
				
				gen currency = "CHF"
				order ym currency
				append using fx_panel_USD
				sort currency ym
				save fx_panel_USD, replace
						
			******************************************
			*** Japan Constant Maturity Par yields ***
			******************************************
		
				*** https://www.mof.go.jp/english/jgbs/reference/interest_rate/index.htm
				import excel using jgbcme_all.xlsx, clear sheet(upload) firstrow 
				keep if year(date) >= 1981
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
			
					**********************************************************************
					***Bootstrap the Japanese zero coupon curve from Japanese CMT yields
					*** CMT yields are semi annual and we treat these as par yields
					*** Procedure:
					*** 1)  Take 6-month discount bill yield from Bloomberg: Use this to compute the price of an 6-month zero-coupon
					*** 2)  Linearly interpolate 1.5 par yield as the average of 1 and 2 year par yields
					*** 3)  Recurisviely solve for zero-coupon prices (the discount function)
					*** 4)  Compute continuously compunded annual yields
					**********************************************		
				
					drop if cmtpy1_0 == .
					
					* Interpolate n.5 par yields as (Y(n) + Y(n+1))/2
					forvalues n = 9(-1)1 {
						local n1 = `n' + 1
						gen cmtpy`n'_5 = (cmtpy`n'_0 + cmtpy`n1'_0)/2
						order cmtpy`n'_*
					}
					order date cmtpy0_5 cmtpy*
					unab varlist: cmtpy*
					foreach var of local varlist {
						replace `var' = `var'/100
					}	
					
					* We only have 6-month yields from Bloomberg beginning in 1999
					* Prior to that assume 6-month and 12-month yields are the same
					replace cmtpy0_5 = cmtpy1_0 if cmtpy0_5 == .
					
					* Initialize bootstrap using 6-month yield
					gen z0_5 = 1/(1+0.5*cmtpy0_5)
					gen sveny0_5 = -100*ln(z0_5)/0.5
					
					* Recurisviely solve for zero-coupon prices and yields
					gen z_sum = z0_5	
					forvalues n = 1/9 {
						gen z`n'_0  = (1 - 0.5*cmtpy`n'_0*z_sum)/(1 + 0.5*cmtpy`n'_0)
						gen sveny`n'_0 = -100*ln(z`n'_0)/`n'		
						replace z_sum = z_sum + z`n'_0
						
						gen z`n'_5  = (1 - 0.5*cmtpy`n'_5*z_sum)/(1 + 0.5*cmtpy`n'_5)
						gen sveny`n'_5 = -100*ln(z`n'_5)/(`n'+0.5)				
						replace z_sum = z_sum + z`n'_5		
					}
					local n = 10
					gen z`n'_0  = (1 - 0.5*cmtpy`n'_0*z_sum)/(1 + 0.5*cmtpy`n'_0)
					gen sveny`n'_0 = -100*ln(z`n'_0)/`n'		
				
					unab varlist: cmtpy*
					foreach var of local varlist {
						replace `var' = `var'*100
					}
					
					/*
					* Plot data to make sure that bootstrapping looks reasonable				
					twoway line cmtpy5_0 sveny5_0 date
					twoway line cmtpy7_0 sveny7_0 date
					twoway line cmtpy10_0 sveny10_0 date
					gen svenf_7to10 = (10*sveny10_0 - 7*sveny7_0)/3
					gen cmtpy_7to10 = (10*cmtpy10_0 - 7*cmtpy7_0)/3
					twoway line cmtpy_7to10 svenf_7to10 date
					* Conclusion: Bootstrapped zero-coupon yields are extremely correlated with par yields
					* and levels are similar since the level of rates in Japan has been so low in recent decades
					* A zero coupon-yield is an equal weighted average of forward short-term rates
					* A par yield is a VW average (involving ZC prices) of future forwards with more distant forwards receiving less weight (assuming positive rates)
					* However, when the level of rates is low the VW average and the EW average are quite similar: Bond math works!
					*/
					
					keep ym sveny*
					drop  sveny*_5
					
					forvalues n = 1/10 {
						rename sveny`n'_0 sveny`n'
					}								
		
				gen currency = "JPY"
				drop if sveny10 == .

				order ym currency
				append using fx_panel_USD
				sort currency ym
				save fx_panel_USD, replace

			*******************************
			***German zero-coupon yields **
			*******************************

			*** Source: https://www.bundesbank.de/en/statistics/money-and-capital-markets/interest-rates-and-yields/term-structure-of-interest-rates-622440

				import excel using bbk_paket1_monthly.xlsx, clear sheet(upload) firstrow
				drop if sveny10 == .
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				gen currency = "EUR"
				order ym currency
				append using fx_panel_USD
				sort currency ym
				save fx_panel_USD, replace
		
			*************************************
			*** Australian zero-coupon yields ***
			*************************************
			
			* Source: Noted in the spreadsheet
			* Sheet 1, from https://www.rba.gov.au/statistics/tables/xls-hist/zcr-analytical-series-hist.xls
			* Sheet 2, from https://www.rba.gov.au/statistics/tables/xls/f17hist.xls

				import excel using aud_yield_curves, clear sheet(output) firstrow
				drop if sveny10 == . 
				keep date sven*
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				gen currency = "AUD"
				order ym currency
				append using fx_panel_USD
				order ym currency
				sort currency ym
				save fx_panel_USD, replace
			
			*****************************
			*** UK zero-coupon yields ***
			*****************************
			
			*** Source: https://www.bankofengland.co.uk/statistics/yield-curves

				import excel using GLC_Nominal_month_end_data_1970_to_Present.xlsx, clear firstrow
				drop if sveny10 == .
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				gen currency = "GBP"
				order ym currency
				append using fx_panel_USD
				sort currency ym
				save fx_panel_USD, replace

			*** Rename foreign zeros as "for" ***
				
				unab svenlist: sven*
				foreach sven of local svenlist {
						rename `sven' for_`sven'
						format for_`sven' %9.4fc
						label var for_`sven' for_`sven'				
				}
				sort currency ym
				save fx_panel_USD, replace

			*****************************
			*** US zero-coupon yields ***
			*****************************
			
			*** Source: https://www.federalreserve.gov/pubs/feds/2006/200628/200628abs.html

				import excel using feds200628.xlsx, clear sheet(upload) firstrow
				drop if sveny10 == .
				gen ym = mofd(date)
				format ym %tm
				sort ym date
				by ym: keep if _n == _N
				keep ym sven*
				unab svenlist: sven*
				foreach sven of local svenlist {
						rename `sven' dom_`sven'
						format dom_`sven' %9.4fc
						label var dom_`sven' dom_`sven'				
				}
				merge 1:m ym using fx_panel_USD
				keep if _merge == 3
				drop _merge
				sort currency ym
				order ym currency for_sven* dom_sven*
				save fx_panel_USD, replace						
		
			****************************************
			*** Merge on FX rates from Bloomberg ***
			****************************************		
			
			import excel using FX_Bloomberg.xlsx, clear sheet(PX_LAST_Upload) firstrow
			
			*** Express all FX rates expressed as USD/FCU (indirect quotes), so higher FX means stronger FCU versus USD	
			
			*** Spot FX rates
			gen FX_AUD = AUD
			gen FX_CAD = 1/CAD
			gen FX_CHF = 1/CHF
			gen FX_EUR = EUR
			gen FX_GBP = GBP
			gen FX_JPY = 1/JPY
			
			gen ym = mofd(date)
			format ym %tm

			drop date
			drop if ym==.
			
			keep ym FX_*
						
			reshape long FX_, i(ym) j(currency) string
			rename FX_ FX
			
			* Take 100* log(FX) so log returns will be in percentage points
			gen fx = 100*log(FX)
			
			merge 1:1 ym currency using fx_panel_USD
			keep if _merge == 3
			sort currency ym
			egen currency_num = group(currency)
			order currency_num ym currency FX fx for_sven* dom_sven*
			xtset currency_num ym
			drop _merge
			xtset currency_num ym
			save fx_panel_USD, replace
			
			** Merge on 3-month government bill yields from Global Financial Data (GFD) **
			import excel using additional_country_data.xlsx, clear sheet(tbill3m_upload) firstrow
			gen ym = mofd(date)
			format ym %tm
			drop date
			drop if ym == .
			reshape long tbill3m_, i(ym) j(currency) string
			rename tbill3m_ for_tbill3m
			replace for_tbill3m = 100*ln(1 + for_tbill3m/100)
			preserve
			drop if currency == "USD"
			merge 1:1 ym currency using fx_panel_USD
			drop if _merge == 1
			drop _merge
			xtset currency_num ym
			save fx_panel_USD, replace

			restore
			keep if currency == "USD"
			drop currency
			rename for_tbill3m dom_tbill3m
			merge 1:m ym using fx_panel_USD
			drop if _merge == 1
			drop _merge
			xtset currency_num ym
			gen yq = qofd(dofm(ym))
			format yq %tq
			save fx_panel_USD, replace
			
			* Drop all data after 2021
			gen year = yofd(dofm(ym))
			keep if year <= 2021
			
  			* Generate forwards and rate spreads
			gen for_svenf_7to10 = (10*for_sveny10 - 7*for_sveny7)/3
			gen dom_svenf_7to10 = (10*dom_sveny10 - 7*dom_sveny7)/3
			
  			* Foreign minus USD rates
			gen for_dom_sveny1 = for_sveny1 - dom_sveny1
			gen for_dom_sveny10 = for_sveny10 - dom_sveny10			
			gen for_dom_svenf_7to10 = for_svenf_7to10 - dom_svenf_7to10
			
			* Compute changes (for programs that don't permit s.x)
			xtset currency_num ym
			local varlist = "fx for_sveny1 dom_sveny1 for_sveny10 dom_sveny10 for_svenf_7to10 dom_svenf_7to10 for_dom_sveny1 for_dom_sveny10 for_dom_svenf_7to10"
			foreach var of local varlist {
					gen s_`var' = s.`var'
					label variable s_`var' "s_`var'"
					gen s3_`var' = s3.`var'
					label variable s3_`var' "s_`var'"
					gen s6_`var' = s6.`var'
					label variable s6_`var' "s_`var'"
					gen s12_`var' = s12.`var'
					label variable s12_`var' "s_`var'"
			}
						
			** 12 month excess returns
			gen rx_fx_12m          = f12s12.fx + (for_sveny1 - dom_sveny1)
			gen for_rx_sveny10_12m = 10*for_sveny10 - 9*f12.for_sveny9 - for_sveny1
			gen dom_rx_sveny10_12m = 10*dom_sveny10 - 9*f12.dom_sveny9 - dom_sveny1
			
			** 3 month excess returns
			** Linear interpolate to generate yields that are 0.25 years shorter **
			gen rx_fx_3m = f3s3.fx + (for_tbill3m - dom_tbill3m)/4
			gen for_rx_sveny10_3m = 10*for_sveny10 - 9.75*(0.75*f3.for_sveny10+ 0.25*f3.for_sveny9) - for_tbill3m/4
			gen dom_rx_sveny10_3m = 10*dom_sveny10 - 9.75*(0.75*f3.dom_sveny10+ 0.25*f3.dom_sveny9) - dom_tbill3m/4
			
			order ym currency currency_num FX fx for_tbill3m for_sveny* dom_tbill3m dom_sveny*		
	
			* Differences in bond excess returns
			gen for_dom_rx_sveny10_3m = for_rx_sveny10_3m - dom_rx_sveny10_3m
			gen for_dom_rx_sveny10_12m = for_rx_sveny10_12m - dom_rx_sveny10_12m
			
			xtset currency_num ym
			format s* for* dom* rx* %9.2f			
			save fx_panel_USD, replace
			
		end
		
		program define load_panel_USD
			use fx_panel_USD, clear
			keep if year >= 2001
			keep if year <= 2021
		end		
			
					
******************************************************************************
**************** Time series notes
******************************************************************************
			
		*** We use Daniel Hoechle xtscc" Driscoll-Kraay standard errors
		*** We use Timothy Vogelsang's "xtsccfixed" to compute fixedb p-values and confidence interals for Driscoll-Kraay standard errors

			** Note xtsccfixedb will only give the same V and SEs as xtscc if, when running xtscc, you specify the "ase" option for "asymptotic standard errors"
			** This option turns off a small ad-hoc finite sample degrees of freedom adjustment used by the baseline version of xtscc
			** This adjustment is (max(T)/(max(T)-1))*((nObs-1)/(nObs - 1 - nVars)) where:
			**      -- max(T) = e(df_r)+1  is the max time-series length across cross-sectional units
			**      -- nObs   = e(N) is the total number of observations in the dataset
			**      -- nVars  =  e(df_m) is the number of independent variables in the regression (excluding constants and/or fixed effects)
			** Also, note that xtscc bases inference on the Student-t distribution with max(T) - nVars -1 = e(df_r) - e(df_m) degrees of freedom
			** This is also well-meaning but is also somewhat of ad-hoc
		
		*** Our practice is to compute SEs and t-statistics using the baseline version of xtscc which uses thos finite sample correction
		*** But then to base p-values and/or confidence intervals off of xtsccfixed which does not use this finite same adjustment	
			
******************************************************************************
**************** Data analysis 
******************************************************************************

		assemble_panel

		load_panel_USD	
		
			** Compute LLSW (2018) bandwidth choices to NW standard errors with KV p-values **
			local rho_z = (2/3)*0.9
			local T = 252
			local S3 =  0.7846*(((2*`rho_z')/(1-`rho_z'^2))^0.5)*(`T'^0.5)
			local S3 = ceil(`S3')
			display `S3'				

			local rho_z = (11/12)*0.9
			local T = 252
			local S12 =  0.7846*(((2*`rho_z')/(1-`rho_z'^2))^0.5)*(`T'^0.5)
			local S12 = ceil(`S12')
			display `S12'

		*************
		** Table I **
		*************

			** Make Table I *
			xtscc s3_fx s3_for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster replace
			xtscc s3_fx s3_for_dom_sveny1 s3_for_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s3_fx s3_for_sveny1 s3_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s3_fx s3_for_sveny1 s3_dom_sveny1 s3_for_sveny10 s3_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_dom_sveny1 s12_for_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_sveny1 s12_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_sveny1 s12_dom_sveny1 s12_for_sveny10 s12_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_I", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			
			** Adjust stars using p-values from the following program: note that this not automatically adjust the output file, which must be done manually *
			xtsccfixedb s3_fx s3_for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_dom_sveny1 s3_for_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_sveny1 s3_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_sveny1 s3_dom_sveny1 s3_for_sveny10 s3_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s12_fx s12_for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_dom_sveny1 s12_for_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_sveny1 s12_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_sveny1 s12_dom_sveny1 s12_for_sveny10 s12_dom_sveny10 if year>=2001 & year<=2021, fe lag(`S12')
		
		**************
		** Table II **
		**************
		
			** Make Table II *
			xtscc s3_fx s3_for_dom_sveny1 					 								if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster replace
			xtscc s3_fx s3_for_dom_sveny1 s3_for_dom_svenf_7to10								if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s3_fx s3_for_sveny1 s3_dom_sveny1 								  			if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s3_fx s3_for_sveny1 s3_dom_sveny1 s3_for_svenf_7to10 s3_dom_svenf_7to10 		if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_dom_sveny1 													if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_dom_sveny1 s12_for_dom_svenf_7to10							if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_sveny1 s12_dom_sveny1 									 	if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
			xtscc s12_fx s12_for_sveny1 s12_dom_sveny1 s12_for_svenf_7to10 s12_dom_svenf_7to10	if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_II", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append
		
			** Adjust stars using p-values from the following program: note that this not automatically adjust the output file, which must be done manually *			
			xtsccfixedb s3_fx s3_for_dom_sveny1 					 								 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_dom_sveny1 s3_for_dom_svenf_7to10								 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_sveny1 s3_dom_sveny1 								  			 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s3_fx s3_for_sveny1 s3_dom_sveny1 s3_for_svenf_7to10 s3_dom_svenf_7to10 	 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb s12_fx s12_for_dom_sveny1 													 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_dom_sveny1 s12_for_dom_svenf_7to10							 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_sveny1 s12_dom_sveny1 									 	 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb s12_fx s12_for_sveny1 s12_dom_sveny1 s12_for_svenf_7to10 s12_dom_svenf_7to10	 if year>=2001 & year<=2021, fe lag(`S12')
							
		***************
		** Table III **
		***************
	
			** Compute LLSW (2018) bandwidth choices to NW standard errors with KV p-values **
			** Bandwidth choices fall by 1 since there are slightly fewer observations in our forecasting regressions * 
			
			local rho_z = (2/3)*0.9
			local T = 249
			local S3 =  0.7846*(((2*`rho_z')/(1-`rho_z'^2))^0.5)*(`T'^0.5)
			local S3 = ceil(`S3')
			display `S3'		

			local rho_z = (11/12)*0.9
			local T = 240
			local S12 =  0.7846*(((2*`rho_z')/(1-`rho_z'^2))^0.5)*(`T'^0.5)
			local S12 = ceil(`S12')
			display `S12'
					
			** Make Table III *
			xtscc for_dom_rx_sveny10_3m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster replace			
			xtscc for_dom_rx_sveny10_3m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_3m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_3m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 	if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_12m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_12m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_12m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			xtscc for_dom_rx_sveny10_12m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_III", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append			
			
			** Adjust stars using p-values from the following program: note that this not automatically adjust the output file, which must be done manually *	
			xtsccfixedb for_dom_rx_sveny10_3m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb for_dom_rx_sveny10_3m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb for_dom_rx_sveny10_3m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb for_dom_rx_sveny10_3m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 	if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb for_dom_rx_sveny10_12m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb for_dom_rx_sveny10_12m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb for_dom_rx_sveny10_12m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb for_dom_rx_sveny10_12m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
				
	
		*************
		** Table IV **
		*************

			** Make Table IV *
			xtscc rx_fx_3m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster replace	
			xtscc rx_fx_3m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_3m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_3m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 	if year>=2001 & year<=2021, fe lag(`S3')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_12m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_12m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_12m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
			xtscc rx_fx_12m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')		
				outreg using "Table_IV", addstat("R-squared", e(r2_w)) adec(2) bdec(2) tdec(2) se 3aster append	
		
			** Adjust stars using p-values from the following program: note that this not automatically adjust the output file, which must be done manually *			
			xtsccfixedb rx_fx_3m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb rx_fx_3m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb rx_fx_3m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb rx_fx_3m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 	if year>=2001 & year<=2021, fe lag(`S3')
			xtsccfixedb rx_fx_12m for_dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb rx_fx_12m for_dom_sveny1 for_dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb rx_fx_12m for_sveny1 dom_sveny1 if year>=2001 & year<=2021, fe lag(`S12')
			xtsccfixedb rx_fx_12m for_sveny1 dom_sveny1 for_svenf_7to10 dom_svenf_7to10 if year>=2001 & year<=2021, fe lag(`S12')
		
